package shard

type ResourceFeature uint
type ResourceStatusType uint

const (
	Read ResourceFeature = iota
	Write
	ReadWrite
)

const (
	Normal = iota
	Busy
	Error
	Cancelled
)

//服务资源:物理资源
type Resource struct {
	Name         string             //资源名、实例id
	Weight       int32              //权重
	Status       ResourceStatusType //状态
	ExtraInfo    map[string]string  //扩展信息
	availability uint               //可用度*100，例如，9999=99.99%，9550=95.5%
	failureCount uint               //失败统计数，包括心跳数量
	totalCount   uint               //总使用数，包括心跳数量
}

//片资源：逻辑资源
type ShardResource struct {
	Resource
	ShardId uint            //片id
	Alias   string          //片别名
	Feature ResourceFeature //读写类型
}

//资源初始化
func (v *ShardResource) Init() *ShardResource {
	v.ExtraInfo = make(map[string]string)
	return v
}

//创建片资源
func NewShardResource() *ShardResource {
	s := new(ShardResource)
	return s.Init()
}

func (v *ShardResource) Equals(r ShardResource) bool {
	if r.ShardId == v.ShardId && r.Name == v.Name && r.Alias == v.Alias {
		return true
	} else {
		return false
	}
}
